<?php
/** Description of gpa_new
  * @package
  * @version 0.1
  * @filesource model_menu.php
  * @author Meta Sanjaya
  * @date 18 Feb 10 7:52:05
  */
class model_menu extends Model
{
    /** @access public
     * @method __construct
     * @param void
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function getMenus($type='main', $parent=0) {
        $menus = $this->db->query("SELECT menu_id, name, url FROM #_menus WHERE type = '$type' AND parent_id = '$parent' AND active = '1'")->rows;

        for($i=0,$j=count($menus);$i<$j;$i++) {
            $menus[$i]['submenus'] = $this->getMenus($type, $menus[$i]['menu_id']);
        }
        
        return $menus;
    }
}

function createMenus($arrayMenus=array(), $sub=false) {
    $return = '';
    if($j=count($arrayMenus)) {
        $return .= '<ul class="' . ($sub ? '' : 'menu') . '">';
        for($i=0;$i<$j;$i++) {
            $hasChild = count($arrayMenus[$i]['submenus']);
            $return .= '<li><a href="' . getHttpUrl() . $arrayMenus[$i]['url'] . '" class="' . ($hasChild ? 'parent' : '') . '"><span>' . $arrayMenus[$i]['name'] . '</span></a>';
            $return .= createMenus($arrayMenus[$i]['submenus'], true);
            $return .= '</li>';
        }
        $return .= '</ul>';
   }
   return $return;
}

function createUserMenus() {
    return(!(User::getUserId())?'<a href="'.getAppUrl('user', 'login').'">Sign In </a> | <a href="'.getAppUrl('user', 'register').'"> Register </a>':'<a href="'.getAppUrl('user', 'logout').'">Sign Out </a>');
}
?>
